﻿using System.Management.Automation;
using System;
using Sitecore.Security.Accounts;

namespace Cognifide.PowerShell.Shell.Commands
{
    [Cmdlet("Get", "User", DefaultParameterSetName = "Name")]
    public class GetUserCommand : BaseCommand
    {

        [Parameter(ValueFromPipeline = true, Position = 0)]
        public string Name { get; set; }

        [Parameter]
        public SwitchParameter Current { get; set; }

        protected override void ProcessRecord()
        {

            if (Current.IsPresent)
            {
                WriteObject(Sitecore.Context.User, false);
            }
                
            if (!String.IsNullOrEmpty(Name))
            {
                WildcardWrite(Name, UserManager.GetUsers(), user => user.Name);
            }
            else
            {
                WriteObject(UserManager.GetUsers(),true);
            }
        }

    }
}